﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Data;
using System.Windows.Controls.Primitives;

namespace MOMKeLABS.Controls.Window
{
    public partial class MinimizBarWindow : UserControl
    {


        public Controls.Window.Window ParentWindow
        {
            get
            {
                return (Controls.Window.Window)GetValue(ParentWindowProperty);
            }

            set
            {
                SetValue(ParentWindowProperty, value);
            }
        }

        public bool IsMinimized { get; set; }

        private static readonly DependencyProperty ImagePathProperty =
            DependencyProperty.Register(
            "ImagePath", typeof(string),
            typeof(MinimizBarWindow), null);

        private static readonly DependencyProperty ParentWindowProperty =
            DependencyProperty.Register(
            "ParentWindow", typeof(Controls.Window.Window),
            typeof(MinimizBarWindow), null);

        public string ImagePath
        {
            get
            {
                return (string)GetValue(ImagePathProperty);
            }

            set
            {
                SetValue(ImagePathProperty, value);

            }
        }


        public MinimizBarWindow()
        {
            InitializeComponent();

            this.DataContext = this;
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            // hook up the binding

            Binding bin = new Binding("State")
            {
                Converter = new Converters.WindowStateTransparenceyConverter(),
                Mode = BindingMode.OneWay,
                Source = this.ParentWindow
            };

            ButtonImage.SetBinding(Image.OpacityProperty, bin);


        }

        private void WindowBtn_Click(object sender, MouseButtonEventArgs e)
        {
            if (this.ParentWindow != null)
            {

                switch (this.ParentWindow.State)
                {
                    case Constants.WindowConstants.WindowState.Maximized:
                        this.ParentWindow.State = Constants.WindowConstants.WindowState.Minimized;
                        break;

                    case Constants.WindowConstants.WindowState.Minimized:
                        this.ParentWindow.State = Constants.WindowConstants.WindowState.Normal;
                        break;

                    case Constants.WindowConstants.WindowState.Normal:
                        this.ParentWindow.State = Constants.WindowConstants.WindowState.Minimized;
                        break;

                }
            }
        }

        private void ButtonImage_MouseEnter(object sender, MouseEventArgs e)
        {
            (sender as Image).Opacity = 1;
        }

        private void ButtonImage_MouseLeave(object sender, MouseEventArgs e)
        {
            if (this.ParentWindow.State != Constants.WindowConstants.WindowState.Minimized)
            {
                (sender as Image).Opacity = (double)App.Current.Resources["MinimizedWigetOpacity"];
            }

        }

        private void ButtonImage_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            // don't bubble the click event up any further to the silverlight framework
            //e.Handled = true;


            
        }

    }



}
